<template>
  <div class="playlist-item column">
    <div class="preview">
      <q-img class="image" :src="value.coverImage" @click="gotoPlaylist">
        <div class="absolute-right column justify-center items-center">
          <div style="font-size: 24px">{{ value.numContents }}</div>
          <q-btn dense size="md" icon="mdi-playlist-play" flat @click="showDetail" />
        </div>
        <template v-slot:error>
          <div class="absolute-full flex flex-center bg-negative text-white">Cannot load image</div>
        </template>
      </q-img>
      <q-btn
        class="bookmark-btn"
        size="10px"
        :icon="value.isPinned ? 'mdi-pin-off' : 'mdi-pin'"
        color="primary"
        style="top: 8px; right: 8px;"
        dense
        @click="addBookmark"
      ></q-btn>
    </div>
    <div class="info-container column q-pa-sm no-wrap">
      <div class="title one-line-text">{{ value.title }}</div>
      <div class="description three-line-text col">{{ value.description }}</div>
      <div class="author-info row justify-between">
        <div class="row justify-center items-center">
          <q-avatar size="18px">
            <img :src="value.creatorAvatar" />
          </q-avatar>
          <div class="creator-name q-ml-xs">{{ value.creatorName }}</div>
        </div>
        <div v-if="value.isLocked">
          <q-icon name="mdi-cloud-lock" style="color: #59B8F8" />
        </div>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { PropType, ref } from 'vue';
import { useRouter } from 'vue-router';
import Playlist from 'src/models/Playlist';
const props = defineProps({
  value: {
    type: Object as PropType<Playlist>,
    required: true,
  }
})
const router = useRouter();
const emit = defineEmits(['detail'])
function addBookmark (event: Event) {
  event.preventDefault();
  console.log('Adding to Bookmark');
}
function showDetail (event: Event) {
  event.stopPropagation();
  emit('detail', event)
}
function gotoPlaylist (event: MouseEvent) {
  router.push({ name: 'Playlist', params: { id: props.value.id } })
}
</script>
<style lang="scss" scoped>
.playlist-item {
  width: 236px;
  height: 256px;
  background-color: #1c1c1c;
  .preview {
    width: 236px;
    height: 136px;
    position: relative;
    .image {
      width: 100%;
      height: 100%;
    }
    .bookmark-btn {
      position: absolute;
      top: 4px;
      right: 4px;
    }
  }
  .info-container {
    width: 100%;
    position: relative;
    .title {
      font-size: 14px;
      width: 100%;
      max-width: 100%;
      line-height: 2em;
    }
    .description {
      width: 100%;
      max-width: 100%;
      font-size: 12px;
      min-height: 4em;
      color: #808080;
    }
    .creator-name {
      font-size: 12px;
      color: #808080;
    }
  }
}
</style>